package yaty.lee.tencent.weibo.util;

import yaty.lee.tencent.weibo.domain.BackInfo;
import yaty.lee.tencent.weibo.exception.AccessTokenExpiredException;

public class ResponseDetectUtil {
    public static void detect(BackInfo info) {
        if (info == null) {
            return;
        }
        switch (info.getRet()) {
        case 0:
            // success
            break;
        case 1:
            oneErrcodeDetect(info);
            break;
        case 2:
            twoErrcodeDetect(info);
            break;
        case 3:
            threeErrcodeDetect(info);
            break;
        case 4:
            fourErrcodeDetect(info);
            break;
        case 5:
            fiveErrcodeDetect(info);
            break;
        case 7:
            sevenErrcodeDetect(info);
            break;
        default:
            break;
        }
    }

    private static void oneErrcodeDetect(BackInfo info) {
        switch (info.getErrcode()) {
        case 1:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷锟矫接匡拷时锟斤拷锟斤拷写锟斤拷clientip锟斤拷锟襟，憋拷锟斤拷为锟矫伙拷锟斤拷锟斤拷实ip锟斤拷锟斤拷锟斤拷为锟斤拷锟斤拷ip锟斤拷锟斤拷127锟斤拷255锟斤拷头锟斤拷ip");
        case 2:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 寰崥鍏у瓒呭嚭闀峰害闄愬埗鎴栫埐绌猴紝寤鸿绺笡瑕佺櫦琛ㄥ収瀹?");
        case 3:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷细锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷写");
        case 4:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 纬锟斤拷值锟斤拷锟斤拷锟斤拷锟斤拷细锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷写");
        default:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg());
        }
    }

    private static void twoErrcodeDetect(BackInfo info) {
        throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg());
    }

    private static void threeErrcodeDetect(BackInfo info) {
        switch (info.getErrcode()) {
        case 0:
            break;
        case 10001:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟劫诧拷锟斤拷client_id");
        case 10002:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟劫诧拷锟斤拷client_secret");
        case 10003:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟劫诧拷锟斤拷response_type");
        case 10004:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟劫诧拷锟斤拷grant_type");
        case 10005:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟劫诧拷锟斤拷redirect_uri");
        case 10006:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟劫诧拷锟斤拷code");
        case 10007:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - client_id锟角凤拷");
        case 10008:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - client_id锟斤拷锟斤拷锟斤拷");
        case 10009:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - client_secret锟斤拷锟饺非凤拷");
        case 10010:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - client_secret锟角凤拷");
        case 10011:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - response_type锟角凤拷");
        case 10012:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - grant_type锟角凤拷");
        case 10013:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - redirect_uri锟角凤拷");
        case 10014:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - redirect_uri锟斤拷锟斤拷锟斤拷code时锟斤拷redirect_uri锟斤拷匹锟斤拷");
        case 10015:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - redirect_uri锟斤拷应锟斤拷注锟斤拷锟絩edirect_uri锟斤拷一锟斤拷");
        case 10016:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - app状态锟斤拷锟斤拷锟斤拷");
        case 10017:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - code锟窖撅拷锟斤拷使锟斤拷");
        case 10018:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - code锟角凤拷");
        case 10019:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - code锟斤拷锟斤拷");
        case 10020:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷取code锟斤拷锟缴癸拷");
        case 10021:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷取accesstoken锟斤拷锟缴癸拷");
        case 10022:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 系统锟节诧拷锟斤拷锟斤拷");
        case 10036:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 缺锟斤拷refresh_token");
        case 10037:
            // 锟斤拷10041锟斤拷说锟斤拷一锟斤拷
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - refresh_token锟角凤拷");
        case 10038:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - refresh_token锟斤拷锟斤拷");
        case 10039:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - refresh_token锟斤拷锟斤拷锟斤拷");
        case 10040:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 刷锟斤拷token锟斤拷锟斤拷锏斤拷锟斤拷锟?");
        case 10041:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - refresh_token锟角凤拷");
        case 10042:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷取refresh_token失锟斤拷");
        case 10043:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷appid锟斤拷权锟斤拷锟斤拷锟斤拷锟斤拷");
        case 30:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷锟斤拷锟絟ttps");
        case 31:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟芥本锟斤拷锟斤拷");
        case 32:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - appkey锟斤拷锟斤拷锟斤拷");
        case 33:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - appkey锟角凤拷");
        case 34:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - appkey and accesstoken do not match.");
        case 35:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - openid锟角凤拷");
        case 36:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - accesstoken锟角凤拷");
        case 37:
            throw new AccessTokenExpiredException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - accesstoken锟斤拷锟斤拷");
        case 38:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - accesstoken锟斤拷锟斤拷锟斤拷");
        case 39:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 锟斤拷锟斤拷确欠锟?");
        case 40:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - the length of accesstoken is illegal.");
        case 41:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 未知锟侥硷拷权锟斤拷锟斤拷");
        default:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg());
        }
    }

    private static void fourErrcodeDetect(BackInfo info) {
        switch (info.getErrcode()) {
        case 0:
            // 表示成功
            break;
        case 4:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 表示有过多脏话");
        case 5:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 禁止访问，如城市，uin黑名单限制等");
        case 6:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 删除时：该记录不存在。发表时：父节点已不存在");
        case 8:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 内容超过最大长度：420字节（以进行短url处理后的长度计）");
        case 9:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 包含垃圾信息：广告，恶意链接、黑名单号码等");
        case 10:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 发表太快，被频率限制");
        case 11:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 源消息已删除，如转播或回复时");
        case 12:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 源消息审核中");
        case 13:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 重复发表");
        case 14:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 未实名认证");
        case 22:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 表示好友最大值满");
        case 23:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 收听对象的听众达到上限");
        case 49:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 添加好友个数为0");
        case 65:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 增加的偶像列表中，有人在我的黑名单中");
        case 66:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 增加的偶像列表中有用户没有开通微博帐户 ");
        case 67:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg() + " - 增加的偶像列表中，你在对方黑名单里（部分或全部）");
        default:
            throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg());
        }
    }

    private static void fiveErrcodeDetect(BackInfo info) {
        throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg());
    }

    private static void sevenErrcodeDetect(BackInfo info) {
        throw new RuntimeException(info.getRet() + "#" + info.getErrcode() + "#" + info.getMsg());
    }
}